package com.myFirstSpringBootDemo.demo.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 使用spring framework 提供的@Value注解获取yml中的属性
 */
@Component
public class Item {

    /**@Value 标签是spring framework 提供的注解，相当于
     * <bean class="com.myFirstSpringBootDemo.demo.pojo.Item">
     *      <property name="itemName" value="子面量/${}从环境变量、配置文件中获取值/#{SpEL}"></property>
     * </bean>
     * value注解支持
     * 1.字面量
     * 2.${}从环境变量、配置文件中获取值
     * 3.#{SpEl}
     */
    @Value("${item.itemName}")
    private String itemName;

    @Value("#{100*2}")
    private Integer itemNumber;

    @Value("true")
    private Boolean isOfficial;

    /**
     * 不支持复杂类型数据封装
     */
    //@Value("${person.map}")
    private Map<String,String> map;


    @Override
    public String toString() {
        return "Item{" +
                "itemName='" + itemName + '\'' +
                ", itemNumber=" + itemNumber +
                ", isOfficial=" + isOfficial +
                '}';
    }

    public Map<String, String> getMap() {
        return map;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public Integer getItemNumber() {
        return itemNumber;
    }

    public void setItemNumber(Integer itemNumber) {
        this.itemNumber = itemNumber;
    }

    public Boolean getOfficial() {
        return isOfficial;
    }

    public void setOfficial(Boolean official) {
        isOfficial = official;
    }
}
